$(function() {
    $("input[name=username]").change(function() {
        var b = $(this).val();
        if (b != "") {
            if (b.length < 4 || b.length>10) {
                layer.alert( "帐户名由4-10个字符组成！");
                return
            }
        }
    });
    $("#btnRegister").click(function() {
        a()
    });
    function a() {
        var g = $("input[name=username]").val() == undefined ? "" : $("input[name=username]").val().trim();
        if (g == "") {
            layer.alert( "请输入账号名称！");
            return
        }
        // var e = $("#aff-key").val();
        // if (e == "") {
        //     layer.alert( "请输入邀请码！");
        //     return
        // }
        var b = $("input[name=mobile]").val();
        var d = new RegExp("^1[3-8][0-9]{9}$");
        if (b !== undefined && (b == "" || !d.test(b))) {
            layer.alert( "请输入正确的11位数字手机号码！");
            return
        }
        var i = $("input[name=wechat]").val();
        var h = new RegExp("^[a-zA-Z0-9-_]+$");
        if (i !== undefined && i.trim() == "") {
            layer.alert( "请输入微信号！");
            return
        } else {
            if (i !== undefined && (!h.test(i) || i.length < 4)) {
                layer.alert( "请输入正确的微信号！");
                return
            }
        }
        var j = $("input[name=password]").val();
        var k = $("input[name=password1]").val();
        if (j == "") {
            layer.alert( "请输入密码！");
            return
        }
        if(j.length<6 || j.length>20){
          layer.alert( "6-20个字母、数字或组合组成，区分大小写！");
          return
        }
        if (j != k) {
            layer.alert( "输入的密码不一致，请重新输入！");
            return
        }
        var c = $("#code").val();
        if (c == "") {
            layer.alert( "请输入验证码！");
            return
        }

        $.post('registration',{
        	username:g,
        	mobile:b,
        	wechat:i,
        	password:j,
        	code:c
        },function(e){
        	if (e.success) {
    			$(".step1").removeClass("on");
    			$(".step2").addClass("on");
				//dialog.alert1("消息",e.message,null,'/index.php/Index/index');
window.location.href="/index.php/Index/index";
			} else {
				layer.alert(e.message);
				var verifyimg = $(".verifyimg").attr("src");
				if(verifyimg.indexOf('?')>0){
					$(".verifyimg").attr("src",verifyimg+'&random='+Math.random());
				}else{
					$(".verifyimg").attr("src",verifyimg+'?random'+Math.random());
				}
			}
        },'json');
    }
});